package puyu.manage.service.common.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import puyu.manage.service.common.config.BaseController;
import puyu.manage.service.common.service.CommonServiceI;
import puyu.manage.service.constant.AjaxResult;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@Api(tags = "公共接口")
@RequestMapping("/system/common")
public class CommonController extends BaseController {

    @Autowired
    CommonServiceI commonServiceI;


    @ApiOperation(value = "获取element树")
    @PostMapping(value = "/getElementTree", produces = { "application/json; charset=UTF-8" })
    public AjaxResult getElementTree(
            @ApiParam(name="params",
                    value="参数集合:element-数据源elementcode;filter-过滤条件;",required=true) @RequestBody Map params
    ) throws Exception{
        String element=(String)params.get("element");
        String filter=(String)params.get("filter");
        List<Map<String, Object>> result = commonServiceI.getElementTree(element,filter);

        return AjaxResult.success(result);
    }

    @ApiOperation(value = "首页汇总数据")
    @PostMapping(value = "/sumData", produces = { "application/json; charset=UTF-8" })
    public AjaxResult sumData(
            @ApiParam(name="params",
                    value="参数集合:filter-过滤条件;",required=true) @RequestParam Map params
    ) throws Exception{
        Map<String, Object> result = commonServiceI.sumData(params);
        return AjaxResult.success(result);
    }

    @ApiOperation(value = "小程序录制视频")
    @PostMapping(value = "/appRecordVideo", produces = { "application/json; charset=UTF-8" })
    public AjaxResult appRecordVideo(
            @ApiParam(name="params",
                    value="参数集合:sampleId-样品id;startTime-开始时间（格式: yyyyMMddHHmmss）;endTime-结束时间（格式:yyyyMMddHHmmss）;",required=true) @RequestBody Map params
    ) throws Exception{
        Map<String, Object> result = commonServiceI.appRecordVideo(params);
        return AjaxResult.success(result);
    }

    @ApiOperation(value = "云视频上传服务器")
    @PostMapping(value = "/uploadVideo", produces = { "application/json; charset=UTF-8" })
    public AjaxResult uploadVideo(
            @ApiParam(name="params",
                    value="参数集合:sampleId-样品id;taskId-任务id;startTime-开始时间（格式: yyyyMMddHHmmss）;endTime-结束时间（格式:yyyyMMddHHmmss）;",required=true) @RequestBody Map params
    ) throws Exception{
        Map<String, Object> result = commonServiceI.uploadVideo(params);
        return AjaxResult.success(result);
    }
}
